package Service;

import Entity.Hotel;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;


public class HotelService {
//	private DatabaseHelper dbHelper;
//	public HotelService(Context context){
//		dbHelper=new DatabaseHelper(context);
//	}
//
	public ArrayList<Hotel> getallHotel(){
		Gson gson=new Gson();
		Map<String, String> map = new HashMap<String,String>();
		map.put("cmd","getall");
		String Json = gson.toJson(map);
		String str=new Transfer_station().transfer(Json);
		ArrayList arr = gson.fromJson(str, ArrayList.class);
		ArrayList<Hotel> hotelarr=new ArrayList<>();
		for(Object tmp:arr){
			Hotel thehotel= gson.fromJson(gson.toJson(tmp), Hotel.class);
			hotelarr.add(thehotel);
		}

		return hotelarr;
	}
	public int searchHotel(String hotelname){
		Gson gson=new Gson();
		Map<String, String> map = new HashMap<String,String>();
		map.put("cmd","search");
		map.put("hotelname",hotelname);
		String Json = gson.toJson(map);
		String str=new Transfer_station().transfer(Json);
		ArrayList arr = gson.fromJson(str, ArrayList.class);
		ArrayList<Hotel> hotelarr=new ArrayList<>();
		int idd=0;
		for(Object tmp:arr){
			Hotel thehotel= gson.fromJson(gson.toJson(tmp), Hotel.class);
			idd=thehotel.getHotelid();
		}
return idd;

	}
	public void makeorder(String hotelid){
		Random rand = new Random();
		Gson gson=new Gson();
		Map<String, String> map = new HashMap<String,String>();
		map.put("cmd","order");
		map.put("hotelid",hotelid);
		int a=rand.nextInt(100);
		map.put("userid", String.valueOf(a));
		String Json = gson.toJson(map);
		String str=new Transfer_station().transfer(Json);


	}

}
